package enumeration;

/**
 * @Package: enumeration
 * @ClassName: Enumeration
 * @Author: x2606
 * @CreateTime: 2022/3/12 17:08
 * @Description: 自定义枚举类
 */

public class CostomEnumeration {
    public static void main(String[] args) {
        System.out.println(Season.AUTUMN);
        System.out.println(Season.SPRING);
    }
}
//实现枚举类
class Season{
    private String name;
    private String desc;

    //属性名通常全部大写，使用final+static获得底层优化
    public final static Season SPRING = new Season("春天","温暖");
    public final static Season SUMMER = new Season("夏天","炎热");
    public final static Season AUTUMN = new Season("秋天","凉爽");
    public final static Season WINTER = new Season("冬天","寒冷");

    //1.构造器私有化，防止new产生新对象。
    //2.去掉set方法，防止属性被修改。
    //3.在内部直接创建固定对象。
    private Season(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    @Override
    public String toString() {
        return "Season{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}
